/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.    
 */
package com.alapham.opens3.server;

import com.alapham.opens3.batch.BatchBackup;

public class Protocol {
	private static final int WAITING = 0;
	private static final int READY = 1;
	private static final int ADDING = 2;
	private static final int REMOVING = 3;
	private static final int BACKING = 4;
	
	private BatchBackup backup = null;
	
	private int state = WAITING;
	
	public String processInput(String inputLine) {
		String outputLine = null;
		
		if(inputLine.equalsIgnoreCase("help"))
		{
			outputLine = "Available Commands:\n start - start_batch backup \n adding_share - add a new share \n removing_share - remove share \n quit - Cleanup and exit";
			return outputLine;
		}
		
		if(state == WAITING)
		{
			outputLine = "OpenS3 Server at your Service!";
			state = READY;
		}
		else if(state >= READY)
		{
			if(inputLine.equalsIgnoreCase("start_batch"))
			{
				outputLine = "starting batch backup";
				state = BACKING;
				backup = new BatchBackup();		
				backup.startBackup();
			}
			else if(inputLine.equalsIgnoreCase("adding_share"))
			{
				outputLine = "Enter path";
				state = ADDING;
			}
			else if(inputLine.equalsIgnoreCase("removing_share"))
			{
				outputLine = "Enter path";
				state = REMOVING;
			}
			else
			{
				outputLine = "Type help for available commands.";
			}
		}
		//TODO add ADDING, REMOVING, BACKING and QUITING
		
		return outputLine;
	}

}
